package com.eddy.proxy.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component("myAspect")
//标注当前MyAspect是一个切面类
@Aspect
public class MyAspect {
    //定义切点表达式
    @Pointcut(value = "execution(* com.eddy.proxy..*.*(..))")
    public void myPointcut(){

    }

    //配置前置通知
    @Before(value = "MyAspect.myPointcut()")
    public void before(){
        System.out.println("前置增强...");
    }

    @AfterReturning(value = "MyAspect.myPointcut()")
    public void afterReturning(){
        System.out.println("后置增强...");
    }
    //ProceedingJoinPoint：正在执行的连接点
    @Around(value = "MyAspect.myPointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("环绕前增强...");
        Object proceed = pjp.proceed();
        System.out.println("环绕后增强...");
        return proceed;
    }

    @AfterThrowing(value = "MyAspect.myPointcut()")
    public void afterThrowing(){
        System.out.println("抛出异常增强...");
    }

    @After(value = "MyAspect.myPointcut()")
    public void after(){
        System.out.println("最终增强...");
    }
}
